package com.juyu.reader.author.common;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class Configure implements ServletContextListener {
	public static String rootPath;
	public static String imagePath;
	public static String htmlPath;

	public static String systemSessionAuthor = "readerAuthor";

	public static String uploadServer;
	public static String uploadTempDir;
	public static String uploadProjectId;
	public static String uploadProjectSecretId;
	public static String uploadProjectSecretKey;
	public static int logLevel;
	public static int serverVersion;

	public static int pageNumber;
	public static boolean redisEnable;
	public static String solrUrl;

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		Properties prop = new Properties();
		InputStream in = arg0.getServletContext().getResourceAsStream("/WEB-INF/classes/readerAuthor.properties");
		try {
			prop.load(in);
			logLevel = Integer.valueOf(prop.getProperty("server.log.level").trim());
			serverVersion = Integer.valueOf(prop.getProperty("server.version").trim());
			uploadServer = String.valueOf(prop.getProperty("upload.server").trim());
			uploadTempDir= String.valueOf(prop.getProperty("upload.temp.dir").trim());
			uploadProjectId = String.valueOf(prop.getProperty("upload.project.id").trim());
			uploadProjectSecretId = String.valueOf(prop.getProperty("upload.project.secret.id").trim());
			uploadProjectSecretKey = String.valueOf(prop.getProperty("upload.project.secret.key").trim());
			pageNumber = Integer.valueOf(prop.getProperty("page.number").trim());
			redisEnable = Boolean.valueOf(prop.getProperty("redis.enable").trim());
			solrUrl = String.valueOf(prop.getProperty("solr.url").trim());
			in.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
		rootPath = arg0.getServletContext().getRealPath("/");
		imagePath = rootPath + "/image/";
		htmlPath = rootPath + "/html/";
	}

}
